<template>
    <div>
        <div class="components_searchs" @keyup.enter="queryTable">
                <span class="tit">作业名称：</span>
                <el-input v-model="table.queryParams.title" auto-complete="off" placeholder="请输入作业名称">
                </el-input>

                <span class="tit">学期：</span>
                <el-select v-model="table.queryParams.semester" clearable placeholder="请选择学期">
                    <el-option
                        v-for="item in semesterList"
                        :key="item.value"
                        :label="item.value"
                        :value="item.value">
                    </el-option>
                </el-select>

                <span class="tit">类型：</span>
                <el-select v-model="table.queryParams.type" clearable placeholder="请选择类型">
                    <el-option
                        v-for="item in homeTypeList"
                        :key="item.id"
                        :label="item.text"
                        :value="item.id">
                    </el-option>
                </el-select>

            <el-button type="primary" icon="el-icon-search" size="mini" @click="queryTable">查询</el-button>
            <el-button type="primary" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </div>

        <vue-table
            :api-url="table.apiUrl"
            :fields="table.fields"
            :appendParams="table.queryParams"
            :content="self"
            ref="homeWorkTable">
        </vue-table>

        <homework-score-detail ref="homeworkScoreDetail"></homework-score-detail>
    </div>
</template>

<script>
    import {enums} from '@/constant'
    import {mapGetters} from 'vuex'
    import moment from 'moment'
    import homeworkScoreDetail from './homework-score-detail'
    export default {
        components: {
            homeworkScoreDetail,
        },
        data() {
            return {
                self: this,
                table: {
                    apiUrl: api.homeworkTeacher.queryTeacherHomework,
                    queryParams: {
                        title: null,   // 作业名称
                        semester: null,   //学期
                        type:null,   // 作业类型
                        status:2    // 已完成作业
                    },
                    fields: [{
                            prop: "__index",
                            label: "序号",
                        },
                        {
                            prop: "title",
                            label: "作业名称",
                        },
                        {
                            prop: "courseName",
                            label: "所属课程",
                        },
                        {
                            prop: "semester",
                            label: "学期",
                        },
                        {
                            prop: "startTime",
                            label: "开始时间",
                            formatter : function(row, column, cellValue){
                                return moment(row.startTime).format('YYYY-MM-DD HH:mm:ss');;
                            }
                        },
                        {
                            prop: "endTime",
                            label: "结束时间",
                            formatter : function(row, column, cellValue){
                                return moment(row.endTime).format('YYYY-MM-DD HH:mm:ss');;
                            }
                        },
                        {
                            prop: "proportion",
                            label: "占比",
                            formatter : function(row, column, cellValue){
                                return cellValue + "%";
                            }
                        },

                        {
                            prop: "__action",
                            label: "操作",
                            actions: [
                                {
                                    label: "查看成绩",
                                    type: "edit",
                                    auth: 'homeworkScore:detail',
                                    func: function(vm, row) {
                                       vm.$refs.homeworkScoreDetail.showDialog(row.id);
                                    }
                                },
                            ]
                        },
                    ],
                },
                // 二级院校列表
                secondSchoolList: null,
                // 专业列表
                professionList: null,
                // 作业类型列表
                homeTypeList: enums.HOMEWORK_TYPE,
                // 学期
                semesterList: null,
            }
        },
        created() {
            this.getSemesterListByDicts();
        },
        mounted() {},
        computed: {
        },
        methods: {
            // 查询学期列表(来自字典)
            getSemesterListByDicts(){
                let vm = this;
                vm.axios.get(api.dictsTypesSubListUrl, {
                     params: {
                        type: "semester_type",
                    }
                }).then((response) => {
                    if (response.data.success) {
                        this.semesterList = JSON.parse(JSON.stringify(response.data.data));
                    } else {
                        vm.$message.error(response.data.msg);
                    }
                })
            },
            queryTable(){
                this.$refs.homeWorkTable.$emit('vuetable:refresh')
            },
            resetQuery(){
                this.table.queryParams.title = null;
                this.table.queryParams.semester = null;
                this.table.queryParams.type = null;
                this.$refs.homeWorkTable.$emit('vuetable:refresh')
            },
        },
    };
</script>
<style scoped>

</style>